package com.hwg.emp.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hwg.emp.common.exception.EmpException;
import com.hwg.emp.model.DeptMD;
import com.hwg.emp.service.DeptService;
import com.hwg.emp.service.ServiceFactroy;
import com.hwg.emp.service.UserService;

public class UpdateDeptController extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		try{
			req.setCharacterEncoding("utf-8");
			resp.setCharacterEncoding("utf-8");
			String id = req.getParameter("id");
			String name = req.getParameter("name");
			//String manager = req.getParameter("manager");
			req.setAttribute("name", name);
			DeptMD dept = new DeptMD();
			dept.setId(id);
			dept.setName(name);
			DeptService deptService = ServiceFactroy.getService(DeptService.class);
			deptService.modifyDept(dept);
			req.getRequestDispatcher("/selectDepts.do").forward(req, resp);
			return;
		} catch (EmpException e) {
			req.setAttribute("message", e.getMessage());
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
			req.setAttribute("message", "系统繁忙,请稍后再试!");
		}
		req.getRequestDispatcher("/pages/updateDept.jsp").forward(req, resp);
	}
	
}
